package com.itheima.练习.test4;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.UUID;

//服务器
public class Server {
    public static void main(String[] args) throws IOException {

        ServerSocket ss=new ServerSocket(10000);
        String str= UUID.randomUUID().toString().replace("-","");
        Socket socket = ss.accept();
        BufferedInputStream bis=new BufferedInputStream(socket.getInputStream());

        BufferedOutputStream bos=new BufferedOutputStream(new FileOutputStream("E:\\java lianxi\\Socket\\src\\main\\图片"+str+".png"));

        byte[] bytes=new byte[2048];
        int b;
        while ((b=bis.read(bytes))!=-1){
            bos.write(bytes,0,b);
        }

        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
        bw.write("上传成功");
        bw.newLine();
        bw.flush();
        socket.close();
    }
}
